/**
 * @file app\tasks\mobus\devices\_set_information.c
 *
 * Copyright (C) 2023
 *
 * _set_information.c is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author HinsShum hinsshum@qq.com
 *
 * @encoding utf-8
 */

/*---------- includes ----------*/
#include "inc/mobus.h"
#include "mobus_device.h"
#include "options.h"
#include "protocol_mobus.h"
#include "resources.h"

/*---------- macro ----------*/
/*---------- type define ----------*/
/*---------- variable prototype ----------*/
/*---------- function prototype ----------*/
static void __tlv_sn_set(mobus_device_t self, tlv_t tlv);

/*---------- variable ----------*/
static struct protocol_callback tlv_set_cbs[] = {
    [SN] = {FIELD_SIZEOF(struct storage_authinfo, sn) - 1, __tlv_sn_set},
};

/*---------- function ----------*/
static void __tlv_sn_set(mobus_device_t self, tlv_t tlv) {
  //    struct dp_storage dp = {
  //        .type = DP_STORAGE_TYPE_AUTH
  //    };

  //    if(tlv->length <= tlv_set_cbs[tlv->type].type) {
  //        self->act->ops.pull(self->act, "storage", &dp, sizeof(dp));
  //        if(tlv->length != strlen((char *)dp.param.auth.sn) ||
  //                memcmp(tlv->value, dp.param.auth.sn, tlv->length)) {
  //            memcpy(dp.param.auth.sn, tlv->value, tlv->length);
  //            dp.param.auth.sn[tlv->length] = '\0';
  //            self->act->ops.notify(self->act, "storage", &dp, sizeof(dp));
  //        }
  //    }
}

static void _set_information(mobus_device_t self, uint8_t* param,
    uint8_t length) {
//    uint8_t off = 0;
//    void (*cb)(mobus_device_t, tlv_t) = NULL;
//    uint8_t types[10] = {0};
//    uint8_t nums = 0;

//    do {
//        types[nums++] = param[off];
//        if(param[off] < ARRAY_SIZE(tlv_set_cbs)) {
//            cb = tlv_set_cbs[param[0]].cb;
//            if(cb) {
//                cb(self, (tlv_t)&param[off]);
//            }
//        }
//        off += sizeof(struct tlv) + param[off + 1];
//    } while(off < length);
//    self->report_information(self, 0xFF, types, nums);
}
